﻿using System;
using System.Diagnostics;
using System.IO;
using System.Net.Sockets;
using System.Text;

namespace BeiKe.PhotoTransfer.Cli
{
    class Program
    {
        static void Main(string[] args)
        {
            //Listen();
            //System.Threading.Thread.Sleep(100);

            //var client = new UdpClient();
            //client.Connect("183.4.177.102", 9000);
            //byte[] buffer = Encoding.UTF8.GetBytes("Hello Udp");
            //client.Send(buffer,buffer.Length);
            //client.Close();
            //System.Threading.Thread.Sleep(1000);

            var fileStream = new FileStream(@"C:\Users\zhongjianyu\Downloads\XYAZ-Setup-3.0.0.6-3.exe", FileMode.Open);
            byte[] bytes = new byte[1024 * 1024];

            while (true) {
                int read_size = fileStream.Read(bytes, 0, bytes.Length);

                Console.WriteLine(read_size);

                System.Threading.Thread.Sleep(100);
            }
        }

        static async void Listen()
        {
            var listener = new UdpClient(9000);
            UdpReceiveResult result = await listener.ReceiveAsync();

            string content = Encoding.UTF8.GetString(result.Buffer);
            
            Console.WriteLine(result.RemoteEndPoint.Address + content);
        }
        static void MemoryStreamTest()
        {
            MemoryStream stream = new MemoryStream();
            byte[] buffer = Encoding.UTF8.GetBytes("Hi2");

            stream.Write(buffer, 0, buffer.Length);

            StreamWriter write = new StreamWriter(stream);

            write.Write("123");

            StreamReader reader = new StreamReader(stream);

            stream.Seek(0, SeekOrigin.Begin);
            //int read_size = stream.Read(buffer, 0, buffer.Length);

            buffer = stream.GetBuffer();
            string a = Encoding.UTF8.GetString(buffer, 0, buffer.Length);
            //string fetch = Encoding.UTF8.GetString(buffer, 0, read_size);
            Console.Write(a);
        }
    }
}
